package com.lmonkey.servlet.product;

import com.lmonkey.servic.CATAGORYDao;
import com.lmonkey.servic.PRODUCTDao;
import com.lmonkey.shop.CATEGORY;
import com.lmonkey.shop.PRODUCT;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;

@WebServlet("/admin/admin_toproductupdate")
public class ToProductUpdate extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置字符集
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=utf-8");
        //获取数据
        int id = Integer.parseInt(request.getParameter("id"));
        //查找
        PRODUCT p = PRODUCTDao.selectByid(id);

        ArrayList<CATEGORY> flist = CATAGORYDao.selectcat("father");
        request.setAttribute("flist",flist);
        ArrayList<CATEGORY> clist = CATAGORYDao.selectcat("child");
        request.setAttribute("clist",clist);
        request.setAttribute("p",p);
        request.setAttribute("keywords",request.getParameter("keywords"));
        request.setAttribute("cp",request.getParameter("cp"));

        request.getRequestDispatcher("admin_productmodify.jsp").forward(request,response);
    }
}
